package com.atguigu.gmall.pay.controller;

import com.alipay.api.AlipayApiException;
import com.atguigu.gmall.common.util.UserAuthUtil;
import com.atguigu.gmall.pay.service.PayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "支付")
@RequestMapping("/api/payment")
@RestController
public class PayController {

    @Autowired
    PayService payService;

    @ApiOperation("获取支付页面")
    @RequestMapping("/alipay/submit/{orderId}")
    public String aliPay(@PathVariable("orderId") Long orderId) throws AlipayApiException {
        Long userId = UserAuthUtil.getUserId();//验证登录
        String page = payService.generatePayPage(orderId,userId);//返回支付页面
        return page;
    }
}
